

<template>
  <div class="bf-commont-template">

    <div class="clearfix bf-top-button">
      <div class="float-l">
        <el-button type="primary" style="margin-left: 10px" @click="showAdd">新增</el-button>
      </div>
      <div class="float-r">
        <div class="float-l">
          <el-input placeholder="请输入部门名称搜索内容" prefix-icon="el-icon-search" v-model="searchData" @keyup.enter.native="quickSearch">
          </el-input>
        </div>
        <div class="float-l padding-l">
          <el-button type="primary" @click="showSearch">高级筛选</el-button>
        </div>
      </div>
    </div>

    <div>
      <bf-table :data="userData" :setting="setting" :rowAction="rowAction" @editSubmit="editSubmit" @pageChange="pageChange" ref="table"></bf-table>
    </div>

    <!-- 添加 -->
    <bf-table-edit :editForm='addSetting' :editRules="editRules" ref='addRef' @formSubmit='addSubmit'></bf-table-edit>
    <!-- 高级搜索 -->
    <bf-table-search :editForm='searchSetting' ref='searchRef' @formSubmit='searchSubmit'></bf-table-search>
    <!-- 编辑 -->
    <bf-table-edit :editForm='editSetting' :editRules="editRules" ref='editRef' @formSubmit='editObj'></bf-table-edit>
    <!--详情-->
    <bf-table-detail ref="bfTableDetail" :editForm="editSetting"></bf-table-detail>

  </div>
</template>

<script>


import {
  getRequireList,
  addRequire,
  deleteObj,
  editSubmit
} from './api.js'
import {
  setting,
  editSetting,
  addSetting,
  searchSetting
} from './table.setting.js'
export default {
  data() {
    return {
      searchSetting: searchSetting,
      searchData: '',
      userData: {},
      setting: setting,
      addSetting: addSetting,
      editSetting: editSetting,
      rowAction: [{
        label: '详情',
        click: (item) => {
          this.$refs.bfTableDetail.show(item.scope)
        }
      }, {
        label: '修改',
        click: (item) => {
          this.$refs.editRef.show(item.scope)
        }
      }, {
        label: '删除',
        click: (item) => {
          this.$refs.table.showDelete(item)
        }
      }],
      editRules: {
        orgId: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        postId: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        postLevel: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        salaryLow: [
          { required: true, message: '必填项', trigger: 'blur' }
        ],
        salaryHigh: [
          { required: true, message: '必填项', trigger: 'blur' }
        ]
      },
      searchParams: { // 搜索条件
        page: 1
      }
    }
  },
  mounted: function() {
    this.searchList()
  },
  methods: {
    searchSubmit(form) {
      // this.searchList(form)
      // console.log(form)
      // return
      this.searchParams.orgId = form.orgId
      this.searchParams.postId = form.postId
      this.searchParams.postLevel = form.postLevel

      this.searchList()
      this.$refs.searchRef.hiden()
    },
    searchList() {
      const pageParams = this.searchParams
      getRequireList(pageParams).then((response) => {
        this.userData = response;
      })
    },
    addSubmit(form) {
      addRequire(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.addRef.hiden()
          this.searchList()
        }
      })
    },
    editObj(form) {
      editSubmit(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功',
            type: 'success'
          })
          this.$refs.editRef.hiden()
          this.searchList()
        }
      })
    },
    // 编辑保存
    editSubmit(params, formType, formList) {
      if (formType === 'delete') {
        const id = params.row.id
        this.deleteItem(id)
      }
    },
    // 删除
    deleteItem(id) {
      const params = {
        id: id
      }

      deleteObj(params).then((response) => {
        if (response.success) {
          this.$message({
            message: '删除成功!',
            type: 'success'
          })
          this.searchList()
        }
      })
    },
    // 分页查询
    pageChange(pageObj) {
      this.searchParams.page = pageObj.page
      this.searchParams.pageSize = pageObj.pageSize
      this.searchList()
    },

    showSearch() {
      this.$refs.searchRef.show()
    },
    showAdd() {
      this.$refs.addRef.show('')
    },
    quickSearch() {
      this.searchParams.page = 1
      this.searchParams.orgName = this.searchData
      this.searchList()
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>

</style>
